package com.lanou.lenanapp.beans;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 15/10/24.
 */
public class Contribution {

    private String wid;
    private String uid;
    private String user_name;
    private String user_avatar;
    private String update_time;
    private String w_sensitive;
    private String comments;
    private String likes;
    private String wbody;

    public static Contribution objectFromData(String str) {

        return new Gson().fromJson(str, Contribution.class);
    }

    public static Contribution objectFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);

            return new Gson().fromJson(jsonObject.getString(str), Contribution.class);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static List<Contribution> arrayContributionFromData(String str) {

        Type listType = new TypeToken<ArrayList<Contribution>>() {
        }.getType();

        return new Gson().fromJson(str, listType);
    }

    public static List<Contribution> arrayContributionFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);
            Type listType = new TypeToken<ArrayList<Contribution>>() {
            }.getType();

            return new Gson().fromJson(jsonObject.getString(str), listType);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return new ArrayList();


    }

    public void setWid(String wid) {
        this.wid = wid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    public void setUser_avatar(String user_avatar) {
        this.user_avatar = user_avatar;
    }

    public void setUpdate_time(String update_time) {
        this.update_time = update_time;
    }

    public void setW_sensitive(String w_sensitive) {
        this.w_sensitive = w_sensitive;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public void setLikes(String likes) {
        this.likes = likes;
    }

    public void setWbody(String wbody) {
        this.wbody = wbody;
    }

    public String getWid() {
        return wid;
    }

    public String getUid() {
        return uid;
    }

    public String getUser_name() {
        return user_name;
    }

    public String getUser_avatar() {
        return user_avatar;
    }

    public String getUpdate_time() {
        return update_time;
    }

    public String getW_sensitive() {
        return w_sensitive;
    }

    public String getComments() {
        return comments;
    }

    public String getLikes() {
        return likes;
    }

    public String getWbody() {
        return wbody;
    }
}
